programming4us
           
 
 
Programming

iPad SDK : New Graphics Functionality - The Basic Drawing Architecture

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/14/2010 3:54:21 PM
Now it's time to talk about how Dudel is going to draw. Instead of dealing with an underlying pixel-buffer canvas on which all operations are performed, we're going to maintain a list of drawing operations, defined by the user's actions. Each object that the user draws will be added to an array, and each of the objects in the array will be drawn when necessary.

For maximum modularity, let's decide that each drawing operation should know how to draw itself. Then all our DudelView class really needs to do is hang onto an array and pass along a draw request whenever it's time to redraw. We'll try to maintain some sort of order here by defining a protocol called Drawable, which contains a single method called draw. Any object that represents a drawing operation should conform to this protocol. Also, there will be times—such as while the user is creating a drawing operation by dragging a finger around the screen—that some temporary drawing will need to be done. The view class won't be responsible for this, however. We'll pass that to our delegate object, the DudelViewController. So, we'll add a method to the DudelViewDelegate method, giving the controller a chance to do some temporary, context-based drawing.

Create a new protocol header file (one of the file types found in the Cocoa Touch Class section of the New File Assistant) in your project, name it Drawable.h, and give it the following content:

//  Drawable.h

@protocol Drawable
- (void)draw;
@end

Now we're ready to flesh out the DudelView class. First, add a few lines to DudelView.h:

//  DudelView.h
#import <UIKit/UIKit.h>

@protocol DudelViewDelegate
- (void)drawTemporary;
@end

@interface DudelView : UIView {
NSMutableArray *drawables;
IBOutlet id <DudelViewDelegate> delegate;
}
@property (retain, nonatomic) NSMutableArray *drawables;
@end

Then define the DudelView.m file as follows:

// DudelView.m
#import "DudelView.h"
#import "Drawable.h"

@implementation DudelView
@synthesize drawables;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
drawables = [[NSMutableArray alloc] initWithCapacity:100];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
drawables = [[NSMutableArray alloc] initWithCapacity:100];
}
return self;
}
- (void)drawRect:(CGRect)rect {
for (<Drawable> d in drawables) {
[d draw];
}
[delegate drawTemporary];
}


- (void)dealloc {
[drawables release];
[super dealloc];
}
@end

You'll notice that we define two different initialization methods. The first is normally called within code; the second is called when an object is being instantiated from a nib file. In our current implementation, only the nib file version is being used, but we may as well cover the other possibility as well.

Apart from that, this code is quite straightforward. Other objects can directly add drawable display operations to the view's array. Whenever drawRect: is called (as a result of someone, somewhere, calling setNeedsDisplay on the view), the view just calls draw everywhere else.

Other -----------------
- jQuery 1.3 : Compact forms (part 6)
- jQuery 1.3 : Compact forms (part 5)
- jQuery 1.3 : Compact forms (part 4)
- jQuery 1.3 : Compact forms (part 3)
- jQuery 1.3 : Compact forms (part 2) - AJAX auto-completion
- jQuery 1.3 : Compact forms (part 1) - Placeholder text for fields
- The Art of SEO : Duplicate Content Issues (part 3)
- The Art of SEO : Duplicate Content Issues (part 2) - How Search Engines Identify Duplicate Content
- The Art of SEO : Duplicate Content Issues (part 1) - Consequences of Duplicate Content
- The Art of SEO : Content Optimization (part 2)
- The Art of SEO : Content Optimization (part 1)
- iPad SDK : New Graphics Functionality - Introducing Dudel (part 2)
- iPad SDK : New Graphics Functionality - Introducing Dudel (part 1)
- iPad SDK : New Graphics Functionality - Bezier Paths
- CSS for Mobile Browsers : Where to Insert the CSS (part 2) - Media queries
- CSS for Mobile Browsers : Where to Insert the CSS (part 1) - Media Filtering
- Developing an SEO-Friendly Website : Keyword Targeting (part 4)
- Developing an SEO-Friendly Website : Keyword Targeting (part 3)
- Developing an SEO-Friendly Website : Keyword Targeting (part 2)
- Developing an SEO-Friendly Website : Keyword Targeting (part 1) - Title Tags
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us